<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
.a1{
    width: 210px;
    border: 1px solid #000000;
    margin: 10px auto;
}
.a1>div{
    width: 50px;
    height: 50px;
    float: left;
    margin: 10px;
    background-color:gold;
}
.clearfix:after,.clearfix:before{ content: "";display: table;}
.clearfix:after{ clear:both;}
</style>
<body>
    <div class="a1 clearfix">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
</div>
</body>
</html>